#!/usr/bin/env python
# encoding: utf-8
"""
#-------------------------------------------------------------------#
#                   CONFIDENTIAL --- CUSTOM STUDIOS                 #     
#-------------------------------------------------------------------#
#                                                                   #
#                   @Project Name : 全球法律项目数据清洗                #
#                                                                   #
#                   @File Name    : compalepackage.py                      #
#                                                                   #
#                   @Programmer   : 李建                            #
#                                                                   #  
#                   @Start Date   : 2020-8-24 9:03                 #
#                                                                   #
#                   @Last Update  : 2020-8-24 9:03                 #
#                                                                   #
#-------------------------------------------------------------------#
# Classes:该程序用于对比两个文件夹，将在文件夹1的file但不在文件夹2的file删除                                                          #
#                                                                   #
#-------------------------------------------------------------------#
"""
import os


def main():
    # 获取文件夹路径
    package1 = input("请输入需要清洗的文件夹路径: ")
    try:
        package1_path = os.path.join(package1)
    except:
        print("input error")
    package2 = input("请输入对比的文件夹路径: ")
    try:
        package2_path = os.path.join(package2)
    except:
        print("input error")
    lpackage1_path = len(package1_path)
    # 遍历需要清洗的文件夹1
    for root, dirs, files in os.walk(package1_path, topdown=False):
        print(root)
        nofilepath = package2_path + '/nofile.txt'
        i = 0
        for file in files:
            package2_path_root = os.path.join(package2_path, root[lpackage1_path+1:])
            Isfind = False
            for root2, dirs2, files2 in os.walk(package2_path_root, topdown=False):
                for file2 in files2:
                    if file == file2:
                        Isfind = True
                        break
                if Isfind:
                    break
            if not Isfind:
                pdfpath = root + '/' + file
                # print(pdfpath)
                # i = i + 1
                # with open(nofilepath, 'a', encoding='utf-8') as f:
                #     f.write(str(i) + '    ' + pdfpath + '\n')
                if os.path.exists(pdfpath):
                    os.remove(pdfpath)


if __name__ == '__main__':
    main()

